package com.xisan.practice.proxy.jdk.proxy;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.time.LocalDateTime;

public class CGLibInterceptor implements MethodInterceptor {
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("cglib计算开始时间" + LocalDateTime.now());
        // 不是反射，是用invokeSuper不是用invoke
        Object object = methodProxy.invokeSuper(o, objects);
        System.out.println("cglib计算结束时间" + LocalDateTime.now());
        return object;
    }
}
